package com.feng.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.feng.entity.User;
import com.feng.service.ServletUser;
import com.feng.util.web.ServletUtil;

public class userLogin extends HttpServlet {


	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		ServletUtil.forword(request, response, "login");
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter("username");
		String pwd = request.getParameter("pwd");
		User u = new ServletUser().findByNameAndPwd(name,pwd);
		if(u!=null){
			ServletUtil.setSessionAttirbute(request, "user", u);
			ServletUtil.redirect(response, "index.jspx");
		}else{
			ServletUtil.setSessionAttirbute(request, "statu", "1001");
			ServletUtil.redirect(response, "index.jspx");
		}
		
	}

}
